
package com.wyzz.hr.action;

import java.util.*;
import org.apache.axis.utils.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.wyzz.hr.base.ComonBeans;
import com.wyzz.hr.bo.IRecruitapplierBo;
import com.wyzz.hr.bo.IRecruitplanBo;
import com.wyzz.hr.pojo.Recruitapplier;
import com.wyzz.hr.pojo.Recruitplan;
import com.wyzz.hr.util.BaseCrit;
import com.wyzz.hr.util.MyTools;
import com.wyzz.hr.util.Pager;


public class RecruitapplierSearch extends RecruitAction {

	public RecruitapplierSearch() {
		applier = new Recruitapplier();
		searchOrExport = null;
		page = new Pager();
	}

	public String execute() throws Exception {
		if (applier == null)
			applier = new Recruitapplier();
		initDrillDownList();
		if ("delete".equals(page.getOperate()))
			if (StringUtils.isEmpty(applierIds)) {
				addActionError("\u53C2\u6570\u9519\u8BEF\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u8BD5\uFF01");
			} else {
				IRecruitapplierBo applierBo = (IRecruitapplierBo) getBean("applierBo");
				applierBo.deleteApplier(applierIds.split(";"));
				addSuccessInfo("\u5220\u9664\u6210\u529F\uFF01");
			}
		page.setOperate(null);
		DetachedCriteria dc = DetachedCriteria
				.forClass(com.wyzz.hr.pojo.Recruitapplier.class);
		org.hibernate.criterion.Criterion tempCrit = Restrictions.or(
				Restrictions.eq(Recruitapplier.PROP_RECA_STATUS, Integer
						.valueOf(16)), Restrictions.or(Restrictions.eq(
						Recruitapplier.PROP_RECA_STATUS, Integer.valueOf(17)),
						Restrictions.or(Restrictions.eq(
								Recruitapplier.PROP_RECA_STATUS, Integer
										.valueOf(18)), Restrictions.eq(
								Recruitapplier.PROP_RECA_STATUS, Integer
										.valueOf(19)))));
		dc.add(tempCrit);
		dc.createAlias(Recruitapplier.PROP_RECA_CREATE_BY, "recaCreateBy", 1);
		dc.createAlias(Recruitapplier.PROP_RECA_LAST_CHANGE_BY,
				"recaLastChangeBy", 1);
		dc.createAlias(Recruitapplier.PROP_RECA_PLAN_ID, "recaPlanId", 1);
		dc.createAlias((new StringBuilder()).append("recaPlanId.").append(
				Recruitplan.PROP_RECP_PB_NO).toString(), "pbNo", 1);
		dc.createAlias(Recruitapplier.PROP_RECA_CHANNEL_NO, "recaChannelNo", 1);
		dc.createAlias(Recruitapplier.PROP_RECA_INTERVIEWER, "recaInterviewer",
				1);
		dc.createAlias(Recruitapplier.PROP_RECA_REFER_EMP_NO, "recaReferEmpNo",
				1);
		dc.createAlias(Recruitapplier.PROP_RECA_RELATION_EMP_NO,
				"recaRelationEmpNo", 1);
		addOrders(dc, page, new String[] { (new StringBuilder()).append(
				Recruitapplier.PROP_RECA_LAST_CHANGE_TIME).append("-down")
				.toString() });
		BaseCrit.addDC(dc, Recruitapplier.PROP_RECA_NAME, "like",
				new String[] { applier.getRecaName() });
		BaseCrit.addDC(dc, Recruitapplier.PROP_RECA_DIPLOMA, "eq",
				new String[] { applier.getRecaDiploma() });
		if (!StringUtils.isEmpty(applier.getCommunication()))
			dc.add(Restrictions.or(Restrictions.ilike(
					Recruitapplier.PROP_RECA_EMAIL, (new StringBuilder())
							.append("%").append(
									applier.getCommunication().trim().replace(
											"\u3000", "")).append("%")
							.toString()), Restrictions.ilike(
					Recruitapplier.PROP_RECA_PHONE, (new StringBuilder())
							.append("%").append(
									applier.getCommunication().trim().replace(
											"\u3000", "")).append("%")
							.toString())));
		if (applier.getRecaPlanId() != null
				&& applier.getRecaPlanId().getRecpPbNo() != null)
			BaseCrit.addDC(dc, Recruitapplier.PROP_RECA_CURR_POSITION, "like",
					new String[] { applier.getRecaPlanId().getRecpPbNo()
							.getPbName() });
		BaseCrit.addDC(dc, Recruitapplier.PROP_RECA_STATUS, "eq",
				new Integer[] { applier.getRecaStatus() });
		BaseCrit.addDC(dc, Recruitapplier.PROP_RECA_GENDER, "eq",
				new Integer[] { applier.getRecaGender() });
		BaseCrit.addDC(dc, Recruitapplier.PROP_RECA_WORK_YEARS, "like",
				new String[] { applier.getRecaWorkYears() });
		IRecruitapplierBo applierBo = (IRecruitapplierBo) getBean("applierBo");
		applierList = applierBo.searchApplierByDc(dc, page, searchOrExport);
		Recruitapplier recApplier;
		for (Iterator i$ = applierList.iterator(); i$.hasNext(); recApplier
				.setAge(MyTools.getAge(recApplier.getRecaBirthDate())))
			recApplier = (Recruitapplier) i$.next();

		if ("export".equals(searchOrExport)) {
			getClass();
			return downloadToExcel(applierList, "ORecruitapplier",
					outmatchModelId);
		} else {
			return "success";
		}
	}

	private void initDrillDownList() {
		String allStatusArr[] = { String.valueOf(2), String.valueOf(11),
				String.valueOf(16), String.valueOf(17), String.valueOf(18),
				String.valueOf(19), String.valueOf(21), String.valueOf(22) };
		allApplierStatus = ComonBeans.getValuesToMap(
				Recruitapplier.PROP_RECA_STATUS, allStatusArr,
				new boolean[] { true });
		String statusArr[] = { String.valueOf(16), String.valueOf(17),
				String.valueOf(18), String.valueOf(19) };
		applierStatus = ComonBeans.getValuesToMap(
				Recruitapplier.PROP_RECA_STATUS, statusArr,
				new boolean[] { true });
		IRecruitplanBo recruitplanBO = (IRecruitplanBo) getBean("recruitplanBO");
		RecruitplanList = recruitplanBO.searchApprovePlanWithCondition(null);
	}

	public List getApplierList() {
		return applierList;
	}

	public void setApplierList(List applierList) {
		this.applierList = applierList;
	}

	public Pager getPage() {
		return page;
	}

	public void setPage(Pager page) {
		this.page = page;
	}

	public Recruitapplier getApplier() {
		return applier;
	}

	public void setApplier(Recruitapplier applier) {
		this.applier = applier;
	}

	public Map getApplierStatus() {
		return applierStatus;
	}

	public void setApplierStatus(Map applierStatus) {
		this.applierStatus = applierStatus;
	}

	public String getSearchOrExport() {
		return searchOrExport;
	}

	public void setSearchOrExport(String searchOrExport) {
		this.searchOrExport = searchOrExport;
	}

	public String getOutmatchModelId() {
		return outmatchModelId;
	}

	public void setOutmatchModelId(String outmatchModelId) {
		this.outmatchModelId = outmatchModelId;
	}

	public Map getAllApplierStatus() {
		return allApplierStatus;
	}

	public void setAllApplierStatus(Map allApplierStatus) {
		this.allApplierStatus = allApplierStatus;
	}

	public List getRecruitplanList() {
		return RecruitplanList;
	}

	public void setRecruitplanList(List recruitplanList) {
		RecruitplanList = recruitplanList;
	}

	public String getApplierIds() {
		return applierIds;
	}

	public void setApplierIds(String applierIds) {
		this.applierIds = applierIds;
	}

	private List applierList;
	private Recruitapplier applier;
	private Map applierStatus;
	private Map allApplierStatus;
	private List RecruitplanList;
	private String searchOrExport;
	private String outmatchModelId;
	public final String outputIoName = "ORecruitapplier";
	private Pager page;
	private String applierIds;
}
